package cn.csc.module.member.dal.mysql.menu;

import java.util.*;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.module.member.dal.dataobject.menu.MemberMenuDO;
import org.apache.ibatis.annotations.Mapper;
import cn.csc.module.member.controller.app.menu.vo.*;

/**
 * 菜单权限 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface MemberMenuMapper extends BaseMapperX<MemberMenuDO> {

    default PageResult<MemberMenuDO> selectPage(AppMemberMenuPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<MemberMenuDO>()
                .likeIfPresent(MemberMenuDO::getName, reqVO.getName())
                .eqIfPresent(MemberMenuDO::getPermission, reqVO.getPermission())
                .eqIfPresent(MemberMenuDO::getType, reqVO.getType())
                .eqIfPresent(MemberMenuDO::getSort, reqVO.getSort())
                .eqIfPresent(MemberMenuDO::getParentId, reqVO.getParentId())
                .eqIfPresent(MemberMenuDO::getPath, reqVO.getPath())
                .eqIfPresent(MemberMenuDO::getIcon, reqVO.getIcon())
                .eqIfPresent(MemberMenuDO::getComponent, reqVO.getComponent())
                .likeIfPresent(MemberMenuDO::getComponentName, reqVO.getComponentName())
                .eqIfPresent(MemberMenuDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MemberMenuDO::getVisible, reqVO.getVisible())
                .eqIfPresent(MemberMenuDO::getKeepAlive, reqVO.getKeepAlive())
                .eqIfPresent(MemberMenuDO::getAlwaysShow, reqVO.getAlwaysShow())
                .betweenIfPresent(MemberMenuDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberMenuDO::getId));
    }

    default List<MemberMenuDO> selectList(AppMemberMenuExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<MemberMenuDO>()
                .likeIfPresent(MemberMenuDO::getName, reqVO.getName())
                .eqIfPresent(MemberMenuDO::getPermission, reqVO.getPermission())
                .eqIfPresent(MemberMenuDO::getType, reqVO.getType())
                .eqIfPresent(MemberMenuDO::getSort, reqVO.getSort())
                .eqIfPresent(MemberMenuDO::getParentId, reqVO.getParentId())
                .eqIfPresent(MemberMenuDO::getPath, reqVO.getPath())
                .eqIfPresent(MemberMenuDO::getIcon, reqVO.getIcon())
                .eqIfPresent(MemberMenuDO::getComponent, reqVO.getComponent())
                .likeIfPresent(MemberMenuDO::getComponentName, reqVO.getComponentName())
                .eqIfPresent(MemberMenuDO::getStatus, reqVO.getStatus())
                .eqIfPresent(MemberMenuDO::getVisible, reqVO.getVisible())
                .eqIfPresent(MemberMenuDO::getKeepAlive, reqVO.getKeepAlive())
                .eqIfPresent(MemberMenuDO::getAlwaysShow, reqVO.getAlwaysShow())
                .betweenIfPresent(MemberMenuDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(MemberMenuDO::getId));
    }

}
